# 从CSV格式的文件中读入数据
fo = open("nba1.txt", encoding="UTF-8")
ls = []
for line in fo:
    line = line.replace("\n", "")
    ls.append(line.split(","))
print(ls)
fo.close()

# 将数据写入CSV格式的文件
ls2 = [['球员', '时间', '得分', '篮板', '助攻', '抢断'], ['勒布朗·詹姆斯', '35', '31', '14', '8', '0'],
       ['安东尼·戴维斯', '36', '27', '6', '0', '4'], ['拉塞尔·威斯布鲁克', '31', '19', '11', '3', '1'],
       ['朗尼·沃克', '29', '5', '3', '5', '1'], ['帕特里克·贝弗利', '25', '3', '2', '2', '3'],
       ['肯德里克·纳恩', '23', '13', '3', '2', '2'], ['斯蒂芬·库里', '33', '33', '6', '7', '4'],
       ['安德鲁·维金斯', '29', '20', '6', '4', '1'], ['克莱·汤普森', '20', '18', '2', '3', '1'],
       ['凯文·卢尼', '21', '7', '6', '2', '1'], ['追梦·格林', '25', '4', '5', '5', '0'],
       ['乔丹·普尔', '28', '12', '2', '7', '2']]
f2 = open("nba2.txt", "w")
for item in ls2:
    f2.write(','.join(item) + '\n')
f2.close()

# 采用二层循环
for row in ls2:
    for column in row:
        print(column)
